$().ready(function() {
	validateRule();
});

var E = window.wangEditor;
var editor = new E('#editor')
editor.customConfig.uploadImgShowBase64 = true;
editor.create();

$.validator.setDefaults({
	submitHandler : function() {
		save();
	}
});
function save() {
	var contentHtml = editor.txt.html();
	if(contentHtml.length == 0) {
		parent.layer.alert("请输入工作描述");
		return false;
	}
	$("#workDescription").val(contentHtml);
	$.ajax({
		cache : true,
		type : "POST",
		url : "/system/work/save",
		data : $('#signupForm').serialize(),// 你的formid
		async : false,
		error : function(request) {
			parent.layer.alert("Connection error");
		},
		success : function(data) {
			if (data.code == 0) {
				parent.layer.msg("操作成功");
				parent.reLoad();
				var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
				parent.layer.close(index);

			} else {
				parent.layer.alert(data.msg)
			}

		}
	});

}
function validateRule() {
	var icon = "<i class='fa fa-times-circle'></i> ";
	$("#signupForm").validate({
		rules : {
			workName : {
				required : true,
				maxlength: 100
			},
			workAddress : {
				required : true,
				maxlength: 100
			},
			workType : {
				required : true,
				maxlength: 100
			},
			workDescription : {
				required : true,
				maxlength: 200
			}
		},
		messages : {
			workName : {
				required : icon + "请输入工作名称",
				maxlength: icon + "工作名称不能超过一百个字符",
			},
			workAddress : {
				required : icon + "请输入工作地点",
				maxlength: icon + "工作地点不能超过一百个字符",
			},
			workType : {
				required : icon + "请输入工作类别",
				maxlength: icon + "工作类别不能超过一百个字符",
			},
			workDescription : {
				required : icon + "请输入工作描述",
				maxlength: icon + "工作描述不能超过两百个字符",
			}
		}
	})
}